package com.bluegalaxy.sitescore.service.impl;

import com.bluegalaxy.sitescore.entity.Role;
import com.bluegalaxy.sitescore.entity.UserRole;
import com.bluegalaxy.sitescore.mapper.RoleMapper;
import com.bluegalaxy.sitescore.mapper.UserRoleMapper;
import com.bluegalaxy.sitescore.service.IRoleService;
import com.bluegalaxy.sitescore.service.support.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 * Role 表数据服务层接口实现类
 *
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implements IRoleService {

	@Autowired
	private UserRoleMapper userRoleMapper;
	@Autowired
	private RoleMapper roleMapper;

	@Override
	public void deleteByUserId(Long userId) {
		UserRole ur = new UserRole();
		ur.setUid(userId);
		userRoleMapper.deleteSelective(ur);
	}

	@Override
	public List<Role> selectRoleList() {
		return roleMapper.selectRoleList();
	}

	@Override
	public Role selectRoleByUid(Long uid) {
		//判断用户角色
		UserRole userRole = new UserRole();
		userRole.setUid(uid);
		//获取角色id
		Long rid = userRoleMapper.selectOne(userRole).getRid();
		Role role = new Role();
		role.setId(rid);
		role = roleMapper.selectOne(role);
		return role;
	}
}